package com.ch.ebusiness.controller.admin;

import com.ch.ebusiness.entity.AUser;
import com.ch.ebusiness.entity.BUser;
import com.ch.ebusiness.service.admin.UserAndOrderAndOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class UserAndOrderAndOutController extends AdminBaseController {
    
    @Autowired
    private UserAndOrderAndOutService userAndOrderAndOutService;
    
    @RequestMapping("/loginOut")
    public String loginOut(@ModelAttribute("aUser") AUser aUser, HttpSession session) {
        session.invalidate();
        return "admin/login";
    }
    
    @RequestMapping("/selectUser")
    public String selectUser(Model model, int currentPage) {
        return userAndOrderAndOutService.selectUser(model, currentPage);
    }
    
    @RequestMapping("/selectUserUpdate")
    public String selectUserUpdate(Model model, int currentPage) {
        return userAndOrderAndOutService.selectUserUpdate(model, currentPage);
    }
    
    @RequestMapping("/selectUserDelete")
    public String selectUserDelete(Model model, int currentPage) {
        return userAndOrderAndOutService.selectUserDelete(model, currentPage);
    }
    
    @RequestMapping("/deleteUser")
    @ResponseBody
    public String deleteUser(Model model, int id) {
        return userAndOrderAndOutService.deleteUser(model, id);
    }
    
    @RequestMapping("/updateUser")
    public String updateUser(@RequestParam("id") String id, Model model, @ModelAttribute("bUser") BUser bUser) {
        model.addAttribute("id", id);
        return "admin/updateUserDetail";
    }
    
    
    @RequestMapping("/updateUserDetail")
    public String updateUserDetail(@ModelAttribute("bUser") BUser bUser) {
        return userAndOrderAndOutService.updateUser(bUser);
    }
    
    @RequestMapping("/selectOrder")
    public String selectOrder(Model model, int currentPage) {
        return userAndOrderAndOutService.selectOrder(model, currentPage);
    }
    
    @RequestMapping("/selectOrderDelete")
    public String selectOrderDelete(Model model, int currentPage) {
        return userAndOrderAndOutService.selectOrderDelete(model, currentPage);
    }
    
    @RequestMapping("/deleteOrder")
    @ResponseBody
    public String deleteOrder(Model model, int id) {
        return userAndOrderAndOutService.deleteOrder(model, id);
    }
}
